package action;
/**
 * 将购物车表中所有的数据查询出来
 */

import dao.CartItemDao;
import po.User;
import vo.CartItemVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(urlPatterns = "/user/action/ShowCartServlet")
public class ShowCartServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.从session中获取user对象
        User user = (User) req.getSession().getAttribute("user");
        //2.调用CartItemDao中的ArrayList<CartItem>selectByUserAssociatedBook(User user)
        CartItemDao cartItemDao = new CartItemDao();
        ArrayList<CartItemVo> list = cartItemDao.selectByUserAssociatedBook(user);
        //3.查询到的数据绑定request
        req.setAttribute("cart",list);
        //4.转发到cart.jsp
        req.getRequestDispatcher("../page/cart.jsp").forward(req,resp);
    }
}
